package model

import (
	"time"
)

type Entity interface {
	IsEmpty() bool
	Load()
}

type AbstractEntity struct {
	ID        string
	CreatedAt time.Time // 创建时间
	UpdatedAt time.Time // 更新时间
	DeletedAt time.Time // 更新时间
	Deleted   bool      // 是否删除
	Created   bool      // 是否已创建
}

func (s *AbstractEntity) IsEmpty() bool {
	return s.ID == "" && !s.Created
}

func (s *AbstractEntity) Load() {

}

func (s *AbstractEntity) OnCreate() {
	s.CreatedAt = time.Now()
	s.Created = true
	s.Deleted = false
}

func (s *AbstractEntity) OnModify() {
	s.UpdatedAt = time.Now()
}

func (s *AbstractEntity) OnDelete() {
	s.DeletedAt = time.Now()
	s.Deleted = true
}
